<template>
  <li 
    :class="[
      'bx-timeline-item',
      {
        'bx-timeline-item--last': isLast,
        'bx-timeline-item--horizontal': layout === 'horizontal'
      }
    ]"
  >
    <div class="bx-timeline-item__tail"></div>
    <div class="bx-timeline-item__dot">
      <slot name="dot">
        <div class="bx-timeline-item__dot-default"></div>
      </slot>
    </div>
    <div class="bx-timeline-item__content bx-glass">
      <div class="bx-timeline-item__header">
        <slot name="label">
          <span v-if="label" class="bx-timeline-item__label">{{ label }}</span>
        </slot>
        <slot name="time">
          <span v-if="time" class="bx-timeline-item__time">{{ time }}</span>
        </slot>
      </div>
      <div class="bx-timeline-item__description">
        <slot></slot>
      </div>
    </div>
  </li>
</template>

<script>
import { computed, inject, getCurrentInstance } from 'vue'

export default {
  name: 'BxTimelineItem',
  props: {
    label: {
      type: String,
      default: ''
    },
    time: {
      type: String,
      default: ''
    }
  },
  setup() {
    const layout = inject('timelineLayout', 'vertical')
    const instance = getCurrentInstance()

    const isLast = computed(() => {
      if (!instance || !instance.parent || !instance.parent.slots.default) return false
      const children = instance.parent.slots.default().filter(vnode => vnode.type.name === 'BxTimelineItem')
      return children[children.length - 1] === instance.vnode
    })

    return {
      layout,
      isLast
    }
  }
}
</script>

<style scoped>
.bx-timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.bx-timeline-item--horizontal {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-right: 20px;
  padding-bottom: 0;
}

.bx-timeline-item__tail {
  position: absolute;
  left: 10px;
  top: 0;
  height: 100%;
  width: 2px;
  background-color: var(--bx-glass-border);
}

.bx-timeline-item--horizontal .bx-timeline-item__tail {
  left: 0;
  top: 10px;
  width: 100%;
  height: 2px;
}

.bx-timeline-item--last .bx-timeline-item__tail {
  display: none;
}

.bx-timeline-item__dot {
  position: absolute;
  left: 0;
  top: 10px;
  transform: translateX(-50%);
  z-index: 1;
}

.bx-timeline-item--horizontal .bx-timeline-item__dot {
  left: 50%;
  top: 0;
  transform: translateY(-50%);
}

.bx-timeline-item__dot-default {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: rgba(0, 122, 255, 0.8);
  border: 2px solid var(--bx-glass-bg);
}

.bx-timeline-item__content {
  margin-left: 20px;
  padding: 12px 16px;
  border-radius: var(--bx-radius-medium);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.bx-timeline-item--horizontal .bx-timeline-item__content {
  margin-left: 0;
  margin-top: 20px;
  text-align: center;
}

.bx-timeline-item__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.bx-timeline-item--horizontal .bx-timeline-item__header {
  flex-direction: column;
  align-items: center;
}

.bx-timeline-item__label {
  font-weight: 600;
  font-size: 15px;
  color: var(--bx-text-primary);
}

.bx-timeline-item__time {
  font-size: 12px;
  color: var(--bx-text-tertiary);
}

.bx-timeline-item__description {
  font-size: 14px;
  color: var(--bx-text-secondary);
  line-height: 1.6;
}

/* Responsive */
@media (max-width: 768px) {
  .bx-timeline-item__content {
    padding: 10px 14px;
  }
  .bx-timeline-item__label {
    font-size: 14px;
  }
  .bx-timeline-item__description {
    font-size: 13px;
  }
}
</style>

